<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        随机生成10个1-15之间不重复的数，放在数组里面
     -->
</head>

<body>

</body>
<script>
    let n = 10;
    let arr = [];
    for (let i = 0; i < n; i++) {
        let num;
        num = parseInt(Math.random() * 15 + 1);
        // console.log(i, num, arr);//测试
        //如果随机数在数组中则重新生成随机数
        while (inArr(num, arr)) {
            num = parseInt(Math.random() * 15 + 1);
        }
        arr[i] = num;
    }
    console.log(arr);


    //判断数在数组中
    function inArr(n, arr) {
        let flag = false;
        for (let i = 0; i < arr.length; i++) {
            if (n == arr[i]) {
                flag = true;
            }
        }
        return flag;
    }
</script>

</html>